import BASE_URL from './api.js'
import store from './../store'
const request = config => {
  // const token = uni.getStorageSync('App-Token')
	const token = store.state.token
	config.header = config.header || {}
  if (token) {
    config.header['Authorization'] = token
  }
  return new Promise((resolve, reject) => {
		console.log(BASE_URL)
    uni.request({
			method: config.method || 'get',
			url: BASE_URL + config.url,
			data: config.data,
			header: config.header,
			success: res => {
				// 接口调用成功
				const code = res.data.code 
				const msg = res.data.msg
				if (code == 200) {
					resolve(res.data)
				}else{
					reject(res.data)
				}
			},
			fail: error => {
				uni.showToast({
					icon: 'none',
					title: '后端接口连接异常'
				})
				reject('后端接口连接异常')
			}
		})
  })
}

export default request
